package com.njlime.setting.repository;

import com.njlime.core.base.repository.impl.BaseDaoImpl;
import com.njlime.core.helper.PageBean;
import com.njlime.core.utils.StringUtil;
import com.njlime.setting.entities.AnnounceCategory;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * 帮助公告分类
 * Created by Dean on 2018-1-16.
 */
@Repository
public class AnnounceCategoryDaoImpl extends BaseDaoImpl<AnnounceCategory> {

    public PageBean categoryList(PageBean pageBean, AnnounceCategory info){
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<>();
        sb.append("select * from t_announce_category where is_del = 0 ");
        if (info.getType() != null) {
            sb.append(" and type = ? ");
            arrList.add(info.getType());
        }
        if (!StringUtil.isEmpty(info.getName())) {
            sb.append(" and name like concat('%',?,'%') ");
            arrList.add(info.getName());
        }
        int num = getListJdbcSize(sb.toString(), arrList);
        pageBean.setTotalCount(num);
        if (num > 0) {
            sb.append(" order by id desc limit ?,?");
            arrList.add((pageBean.getCurPage() - 1) * pageBean.getPageSize());
            arrList.add(pageBean.getPageSize());
            pageBean.setMapList(getListJdbc(sb.toString(), arrList));
        }
        return pageBean;
    }

}
